package Ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Delete implements Ioperate{
    @Override
    public void operate(BookList bookList) {
        int curSize = bookList.getCurSize();
        if(curSize == 0){
            System.out.println("书架已空，无法继续删除......");
        }

        System.out.println("请输入你要删除图书的书名：");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();

        for (int i = 0; i < curSize; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                System.out.println("删除成功......");
                for (int j = i; j < curSize - 1; j++) {
                    bookList.setBooks(j,bookList.getBooks(j+1));
                }
                bookList.setCurSize(curSize - 1);
                return;
            }
        }

        System.out.println("未查询到该书.....");
    }
}
